#!/usr/bin/perl
#
# Snapshot some value to the statistics file
#
use Counter;
use Getopt::Long;

my $table = shift;
my $qualrow = shift;

my $stats = Counter::openfile("statistics");

@counts = $stats->selectany("count(*) as c, $qualrow as r, now() as n
 from $table group by $qualrow");
my $date;

for $count (@counts) {
    my $stat = $stats->newnum();
    $date = $$count{n}; # save for use after loop
    $stat->{name} = $table;
    $stat->{qualifier} = "$qualrow=$$count{r}";
    $stat->{date} = $$count{n};
    $date = $$count{n} if !$date;
    $stat->{value} = $$count{c};
    $stat->{comment} = "Database snapshot";
    $stat->store();
    $total += $$count{c};
}
my $stat = $stats->newnum();
$stat->{name} = $table;
$stat->{qualifier} = '';
$stat->{date} = $date;
$stat->{value} = $total;
$stat->{comment} = "Database snapshot";
$stat->store();

    

